<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
var searchData =function()
{
	$.ajax({
		url:'${request.contextPath}/user/getUserList.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		data:{
			'pageNum':$('#pageNum').val(),
			'pageSize':$('#pageSize').val(),
			'userName':$('#userName').val()
		},
		success:function(html)
		{
			$('#dataDiv').html(html);
		}
	});
}

//打开添加用户的模态框
var addUserDiv = function()
{
	$.ajax({
		url:'${request.contextPath}/user/preAddUser.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		success:function(html)
		{
			$('#windowDiv').html(html);
			$('#addModal').modal();
		}
	});
	
}

//添加用户
var addUserFn = function()
{
	$.ajax({
		url:'${request.contextPath}/user/addUser.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:$('#addForm').serialize(),
		success:function(data)
		{
			alert(data.msg);
			if(data.success==1)
			{
				searchData();
				$('#addModal').modal('hide');
			}
		}
	});
}

//pre编辑用户
var preEditUserFn = function(uid)
{
	$.ajax({
		url:'${request.contextPath}/user/preEditUser.htm',
		type:'post',
		dataType:'html',
		data:{
			'userId':uid
		},
		async:'false',
		cache:false,
		processData:true,
		success:function(html)
		{
			$('#windowDiv').html(html);
			$('#editModal').modal();
			
		}
	});
}

//编辑用户
var editUserFn = function()
{
	$.ajax({
		url:'${request.contextPath}/user/editUser.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:$('#editForm').serialize(),
		success:function(data)
		{
			alert(data.msg);
			if(data.success==1)
			{
				searchData();
				$('#editModal').modal('hide');
			}
		}
	});
}

//删除用户
var removeUser = function(uid)
{
	if(!confirm('确定删除该用户么！'))
	{
		return false;
	}
	$.ajax({
		url:'${request.contextPath}/user/removeUser.htm',
		type:'post',
		dataType:'json',
		data:{
			'userId':uid
		},
		async:'false',
		cache:false,
		processData:true,
		success:function(data)
		{
			alert(data.msg);
			searchData();
		}
	});
}
searchData();
</script>
</head>
<body style="overflow: scroll;overflow-x:hidden;">
   <span class="cp_title">用户管理</span>
   <br/>
   <br/>
   <form id="serchForm" class="bs-example bs-example-form" style="margin-left:50px">
      <div class="row">
        <div class="input-group">
		   <input type="hidden" id="pageNum" name="pageNum" value="1"/>
   		   <input type="hidden" id="pageSize" name="pageSize" value="10"/>
		   <input type="text" id="userName" name="userName" value="" placeholder="请输入用户名">
		   
		   <button type="button" class="btn btn-info" value="" onclick="searchData();">查询</button>
	   	   <button type="button" class="btn btn-primary" onclick="addUserDiv();" data-toggle="modal">新增用户</button>
        </div>
      </div>
   </form>
   
    <!--模态框-->

   <div id="dataDiv">
   </div>
 
   <div id="windowDiv">
   
   </div>


</body>
</html>
